<div class="container">

    <div class="page-title ui-widget-content ui-corner-all head">
        <div class="headLeft">
            <h1 class="icon-category">Quản lý Users</h1>
        </div>
        <div class="headRight">
            <div id="toolbar" class="toolbar-list">
                <ul>
                    <li id="toolbar-new" class="button">
                        <a class="toolbar"  href="<?php echo base_url('cp/users/add') ?>"><span class="icon-32-new"></span>&nbsp;&nbsp;New</a>
                    </li>
                    <li id="toolbar-trash" class="button">
                        <a class="toolbar ui-icon-trash" href="javascript:void(0)"><span class="icon-32-trash"></span>&nbsp;&nbsp;Trash</a>
                    </li>

                </ul>
            </div>
        </div>
    </div>
    <div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all form-container">
        <div class="portlet-header ui-widget-header" id="search-post" style="cursor: pointer;"><span class="ui-icon ui-icon-circle-arrow-s"></span>
            Tìm kiếm crawler</div>
        <div class="portlet-content" style="display: block;">
            <form id="formSearch" class="forms" method="get" action="<?php echo base_url('cp/users'); ?>">
                <table class="searchForm">
                    <tbody>
                        <tr>
                            <td><label class="desc">Từ khóa:</label></td>
                            <td><input type="text" value="<?php echo @$param['keyword']; ?>" style="width:155px;" class="field text" name="keyword"></td>
                            <td><label class="desc">Từ ngày:</label></td>
                            <td><input type="text" name="fromdate" value="<?php echo @$param['fromdate']; ?>" </td>
                        </tr>
                        <tr>
                            <td><label class="desc">Email:</label></td>
                            <td><input type="text" value="<?php echo @$param['email']; ?>" style="width:155px;" class="field text" name="email"></td>
                            <td><label class="desc">Đến ngày:</label></td>
                            <td><input type="text" name="todate" value="<?php echo @$param['todate']; ?>" </td>
                        </tr>
                        <tr>
                            <td colspan="8"><input type="submit" name="dosearch" class="submit" value="Tìm kiếm"></td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>

    <div class="hastable">
        <?php
        if ($this->session->flashdata('result') != ''){
            echo $this->session->flashdata('result');
        }
        ?>
        <?php echo form_open('cp/users/deleteList',"class='pager-form' id='formlist' name='myform'");?>

        <table>
            <thead>
            <tr>
                <th style="border-left:0px;"><input type="checkbox" class="submit" onclick="this.value=check(this.form['id[]'])" value="check_none"></th>
                <th align="left">Username</th>
                <th>Email</th>
                <th>Ngày đăng ký</th>
                <th>Trạng thái</th>
                <th style="width: 8%;">Action</th>
            </tr>
            </thead>
            <tbody>
            <?php if(count($records)){
                foreach($records as $key=>$item){
            ?>
                <tr>
                    <td class="center" style="border-left:0px;">
                        <input type="checkbox" value="<?php echo $item['id']; ?>" name="id[]" class="checkbox">
                    </td>
                    <td><?php echo $item['username']; ?></td>
                    <td><?php echo $item['email']; ?></td>
                    <td><?php echo date('d-m-Y H:i:s',$item['createdTime']); ?></td>
                    <td><?php echo $item['status']; ?></td>
                    <td>
                        <div style="margin: 0 auto;">
                            <a class="btn_no_text btn ui-state-default ui-corner-all edit" href="<?php echo base_url('cp/category/edit/'.$item['id']); ?>" >
                                <span class="ui-icon ui-icon-pencil"></span></a>
                            <a class="btn_no_text btn ui-state-default ui-corner-all delete" href="javascript:void(0)" datafld="<?php echo $item['id'] ?>"><span class="ui-icon ui-icon-trash"></span></a>
                        </div></td>

                </tr>
                    <?php } } ?>
            </tbody>
        </table>

        <?php echo form_close();?>
    </div>
    <div class="pagination">
        <?php echo $pagination ?>   </div>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $(".hastable .ui-icon-trash").parent().click(function(){
            if(!confirm("Bạn chắc chắn muốn xóa không?")) {
                return false;
            }
            var id = $(this).attr('datafld');
            jQuery.ajax({
                type: "GET",
                async: false,
                dataType:'json',
                url: base_url + "/category/delete/"+id,
                data: "",
                success: function(data){

                    window.location.reload();
                }
            });
        });

        $(".button .ui-icon-trash").parent().click(function(){
            if($("input:checked").length>0){
                if(!confirm("Bạn chắc chắn muốn xóa không?")) {
                    return false;
                }
                $("#formlist").submit();
            }else{
                alert("Bạn chưa chọn bản nghi để xóa!")

            }
        });

        jQuery('#parent').change(function(){
            var id = $('#parent option:selected').val();
            jQuery.ajax({
                type: "GET",
                async: false,
                dataType:'json',
                url: base_url + "/category/get_subcats/"+id,
                data: "",
                success: function(data){
                    console.log();
                    jQuery('#child').html(data['option']);

                }
            });
        });

    });
</script>